# TabsMenu - Implements horizontal menu that can be used as tabs
# Copyright (C) 2007 Lauri Taimila
# 
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

__licence__ = "GPLv2"
__copyright__ = "2007, Lauri Taimila"
__author__ = "Lauri Taimila <lauri@taimila.com>"

import clutter
from frontend.gui.widgets.selector import Selector
from frontend.gui.widgets.grid_menu import GridMenu

class TabsMenu(GridMenu):
    """
    TabsMenu widget
    
    This widget inherits genral GridMenu widget and implements simple horizontal
    menu. This menu can be used as tabs
    """
    
    def __init__(self, theme, animate):
        """Initialize widget"""
        GridMenu.__init__(self)
        
        self.orientation = self.HORIZONTAL
        self.row_count = 1                  # Items per row
        self.visible_cols = 2               # Number of visible columns
               
        self.animate = animate              # Animate this widget behaviour
        self.set_item_size(570, 60)         # Default size for textmenu item
        
        # Set Cursor
        c = clutter.Rectangle()
        c.set_color((0,0,0,0))
        self.set_cursor(c)
        
    def _update_selected_item(self, new_location, old_location=None):
        """
        Overridden method! See GridMenu API reference.
        @param new_location: Logical location of current menuitem
        @param old_location: Logical location of last menuitem
        """
        if old_location is not None:
            self.items[old_location].set_active(False)
        self.items[new_location].set_active(True)
        
    def _animate_items_on_state_change(self):
        """
        This method is called when widget is set active or inactive. This method
        allows widget to react this action.
        """
        
        if self.active:
            self.set_scale(1.0, 1.0)
            for item in self.items:
                item.set_opacity(255)
        else:
            self.set_scale(0.95, 0.95)
            for item in self.items:
                item.set_opacity(64)
            self.items[self.logical_position].set_opacity(192)